package org.cvcsc.weproject.service;

import org.cvcsc.weproject.domain.Clazz;
import org.cvcsc.weproject.domain.Student;
import org.cvcsc.weproject.domain.StudentNameNumber;
import org.cvcsc.weproject.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class StudentService {

    @Autowired
    private StudentRepository studentRepository;

    // ... 其他代码保持不变 ...

    public void importStudentsForClazz(Clazz clazz, List<StudentNameNumber> listOfstudentNameNumber) {
        if (clazz == null || listOfstudentNameNumber == null || listOfstudentNameNumber.isEmpty()) {
            throw new IllegalArgumentException("学生列表不能为空");
        }
        List<Student> list = (listOfstudentNameNumber).stream().map(info -> Student.createBy(clazz, info))
                .collect(Collectors.toList());
        ;
        // 保存学生信息
        studentRepository.saveAll(list);
    }

    public void deleteAllStudentsByClazzId(Long clazzId) {
        this.studentRepository.deleteStudentsByClazzId(clazzId);
    }

}
